package com.naiterui.ehp.bs.agent.controller.inner;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.utils.thread.ThreadPoolUtil;
import com.naiterui.ehp.bs.agent.service.IAsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 报告
 * 
 * @author yangfuya
 * @since 2022/2/17
 */
@Slf4j
@Api(tags = "报告")
@AllArgsConstructor
@RestController
@RequestMapping("/inner/report")
public class InnerReportController {

    private final IAsService asService;

    @ApiOperation("生成报告")
    @PostMapping("generate")
    private void generate(String reportDate) {
        log.info("每日报告生成");
        ThreadPoolUtil.execute(() -> {
            try {
                this.asService.generateReport(reportDate);
                this.asService.generateSummaryReport();
            } catch (BusinessException e) {
                log.error("每日报告生成失败: {}", e.getMessage());
            }
        });
    }
}
